package com.efuture.javacall; /* @Description:
 * @Auther: zhaoshanshan
 * @Date: 2022/03/11/11:01 下午
 */

/**
 * @description: java版本的单例模式 对应Kotloin的demo124
 * @author: zhaoshanshan
 * @create: 2022-03-11 23:01
 **/
public class demo124 {

    //1.饿汉式
//    private demo124(){}
//    private static demo124 instantance = new demo124();//直接类加载的时候 创建对象
//    public static demo124 getInstance(){
//        return instantance;
//    }
    //2 懒汉式
//    private demo124(){}
//    private static demo124 instantance = null;
//    public static demo124 getInstance(){
//        if(null==instantance){
//            instantance = new demo124();
//        }
//        return instantance;
//    }
//    //3.安全校验单例模式
//    private demo124(){}
//    private static demo124 instantance = null;
//    public static demo124 getInstance(){
//        synchronized (demo124.class){
//            if(null==instantance){
//                instantance = new demo124();
//            }
//        }
//        return instantance;
//    }
    //4 双重安全校验

    private demo124(){}
    private static volatile demo124 instantance;//volatile关键字需要学习
    public static demo124 getInstance(){
            if(null==instantance){
                synchronized (demo124.class) {
                    instantance = new demo124();
                }
        }
        return instantance;
    }


}
